package com.koron.sinoprobe.web.ledger.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.sinoprobe.web.ledger.bean.entity.SpContractRecord;
import com.koron.sinoprobe.web.ledger.service.SpContractRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author twcao
 * @title: SpContractRecordRecordController
 * @projectName GDH_EAM_V2
 * @description: 
 * @date 2021/12/617:05
 */
@Slf4j
@RestController
@RequestMapping("/sp/project/contractRecord/")
@Api(tags = "专项台账-合同付款记录")
public class SpContractRecordController {

    @Autowired
    private SpContractRecordService recordService;

    @GetMapping("/selectOne")
    @ApiOperation("合同付款记录详情查询")
    @ApiImplicitParam(name = "id", value = "合同付款记录id", required = true)
    public Response<SpContractRecord> selectOne(@CasUser @ApiIgnore EamUser user, @RequestParam String id) {
        SpContractRecord detail = ADOConnection.runTask(user.getCurrDs(), recordService, "queryById", SpContractRecord.class, id);
        return Response.ok("查询成功", detail);
    }

    @GetMapping("/queryList")
    @ApiOperation("合同付款记录分页查询， 未分页")
    public Response<PageInfo<SpContractRecord>> queryList(@CasUser @ApiIgnore EamUser user, SpContractRecord query) {
        List<SpContractRecord> list = ADOConnection.runTask(user.getCurrDs(), recordService, "queryList", List.class, query);
        return Response.ok("查询成功", new PageInfo<>(list));
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("新增或修改合同付款记录(批量，新增前，会删除合同先前的所有记录)")
    public Response<Integer> saveOrUpdate(@CasUser @ApiIgnore EamUser user, @RequestBody List<SpContractRecord> list) {
        int row = ADOConnection.runTask(user.getCurrDs(), recordService, "saveOrUpdate", Integer.class, list);
        return Response.ok("保存成功", row);
    }

    @GetMapping("/deleteById")
    @ApiOperation("根据id删除合同付款记录")
    @ApiImplicitParam(name = "id", value = "合同付款记录id", required = true)
    public Response<String> deleteById(@CasUser @ApiIgnore EamUser user, @RequestParam String id) {
        ADOConnection.runTask(user.getCurrDs(), recordService, "deleteById", Boolean.class, id);
        return Response.ok("删除成功", id);
    }
}
